<?php
    require_once("SmartyReady.php");
    require_once("usuario.php");
    require_once("mp3.php");
    require_once("playlists.php");
    // Preparem l'smarty
    $sm = new SmartyReady();
    $sm->muntarTemplates();
    // Preparem sessio
    session_start();
    if (!empty($_SESSION['username'])) {
        $sm->assign('banner','bannerUser.tpl');
        $sm->assign('usuari',$_SESSION['username']);
        $sm->assign('pathAvatar',$_SESSION['avatar']);
        $sm->assign('cuerpo','confplaylist.tpl');
      
        if(!empty($_POST['playlist'])) {
            $playlist = new Playlists();
            $playlist->set_nom($_POST['playlist']);
            $user = Usuario::findByUsername($_SESSION['username']);
            $id = $user->get_id();
            $playlist->set_idusuari($id);
            $playlist->insert();
            $sm->assign('textplay',"La playlist s'ha creat satisfactoriament");
        }
        else {
            $sm->assign('textplay','');
        }
    }
    else {
        // T'has colat a la pagina XXX sense estar logejat
        $sm->assign("banner","login.tpl");
        $sm->assign('resultatLogin','');
        $sm->assign('cuerpo','buit.tpl');
        ?><meta http-equiv="Refresh" content="0;url=./index.php"><?php
    }
    $sm->display("E:/wamp/www/JediMusic/Smarty/templates/base.tpl");
?>
